import React,{Component} from 'react';

class DDView extends Component {
    constructor(props){
        super(props)

    }

    scrollFunc(e2){
        if (!this.props.canAction){
            return;
        }
        
        // console.log(e2)
        e2.stopPropagation();

        let dom=e2.target;
        // scrollHeight 这个div内dom整个高度
        // scrollTop 被卷掉的高度
        // clientHeight 你能看见的高度

        if (dom.scrollHeight-dom.scrollTop-dom.clientHeight < (this.props.distance || 1))
        {
            this.props.action();
        }
        
    }

    render(){
        
        return (
            <div className={this.props.className || ''} style={this.props.style || {}} onScroll={this.scrollFunc.bind(this)}>
                {this.props.children}
            </div>
        )
    }
}

export default DDView